package org.niu.str;

import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.Arrays;

public class CompareVersion {
    public int compare (String version1, String version2) {
        // write code here
        String[] t1 = version1.split("\\.");
        String[] t2 = version2.split("\\.");
        int n1 = t1.length;
        int n2 = t2.length;
        int n = Math.max(n1,n2);
        String[] v1 = new String[n];
        String[] v2 = new String[n];
        Arrays.fill(v1,"0");
        Arrays.fill(v2,"0");
        for (int i = 0; i < n1; i++) {
            v1[i] = t1[i];
        }
        for (int i = 0; i < n2; i++) {
            v2[i] = t2[i];
        }
        for (int i = 0; i < n; i++) {
            if(new BigInteger(v1[i]).compareTo(new BigInteger(v2[i]))<0){
                return -1;
            }else if(new BigInteger(v1[i]).compareTo(new BigInteger(v2[i]))>0){
                return 1;
            }else{
                continue;
            }
        }
        return 0;
    }
}
